<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>登录页面</title>
  <style>
    body {
      background-color: #f5f5f5;
      font-family: Arial, Helvetica, sans-serif;
    }
    .container {
      width: 100%;
      max-width: 500px;
      margin: 0 auto;
      padding: 20px;
      box-sizing: border-box;
      background-color: #fff;
      box-shadow: 0 0 10px rgba(0,0,0,0.2);
      border-radius: 5px;
    }
    h1 {
      text-align: center;
      margin-top: 0;
    }
    form {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 10px;
    }
    input {
      width: 100%;
      padding: 10px;
      box-sizing: border-box;
      border-radius: 5px;
      border: none;
      background-color: #f0f0f0;
      font-size: 16px;
      color: #333;
    }
    button {
      width: 100%;
      padding: 10px;
      box-sizing: border-box;
      border-radius: 5px;
      border: none;
      background-color: #007bff;
      color: #fff;
      font-size: 16px;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>登录</h1>
    <form>
      <label for="username">用户名</label>
      <input type="text" id="username" name="username" required>
      <label for="password">密码</label>
      <input type="password" id="password" name="password" required>
      <button type="submit">登录</button>
    </form>
  </div>
  <script>
    const form = document.querySelector('form');
    form.addEventListener('submit', async (event) => {
      event.preventDefault();
      const username = form.elements.username.value;
      const password = form.elements.password.value;
      // 发送登录请求
      const response = await fetch('/login', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ username, password })
      });
      const data = await response.json();
      if (data.success) {
        // 登录成功，跳转到首页
        window.location.href = '/home';
      } else {
        // 登录失败，显示错误信息
        alert(data.message);
      }
    });
  </script>
</body>
</html>